<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page language="java" contentType="text/html"%>

<html>

<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="../css/base.css" media="all" />
	
<%
//String view = view;
	String view = "";
%>
</head>

<body id="wrap">
<jsp:include page="../bizring_header1.jsp"/>
	<div id="container">
		<!-- left-->		
	    <h2 class="hidden">sub_menu</h2>
		<div id="left_part">
			<div id="left_menu">
<%if(view == null || view.equals("")){%>
				<ul>
					<p><img src="../images/biz-ring/left_title.gif" alt="Biz-Ring" /></p>
					<li><a href="whatis.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image23','','../images/biz-ring/left_menu01_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image23','','../images/biz-ring/left_menu01_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu01_off.gif" name="Image23" width="161" border="0" id="Image23" alt="What is Biz-Ring" /></a></li>
					<li><a href="biz-ring.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image22','','../images/biz-ring/left_menu02_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image22','','../images/biz-ring/left_menu02_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu02_off.gif" name="Image22" width="161" border="0" id="Image22" alt="Biz-Ring Now" /></a></li>
					<li><a href="Advertising Schedule_list.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image24','','../images/biz-ring/left_menu03_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image24','','../images/biz-ring/left_menu03_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu03_off.gif" name="Image24" width="161" border="0" id="Image24" alt="Advertising Schedule" /></a></li>
					<li><a href="notice_list.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image25','','../images/biz-ring/left_menu04_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image25','','../images/biz-ring/left_menu04_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu04_off.gif" name="Image25" width="161" border="0" id="Image25" alt="Notice" /></a></li>
					<li><a href="price.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image26','','../images/biz-ring/left_menu05_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image26','','../images/biz-ring/left_menu05_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu05_off.gif" name="Image26" width="161" border="0" id="Image26" alt="Price Notice" /></a></li>
				</ul>
<%}
else if(view.equals("k")){%>
				<ul>
					<p><img src="../images/biz-ring/left_title.gif" alt="Biz-Ring" /></p>
					<li><a href="whatis.html?view=k" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image23','','../images/biz-ring/left_menu01_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image23','','../images/biz-ring/left_menu01_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu01_off.gif" name="Image23" width="161" border="0" id="Image23" alt="What is Biz-Ring" /></a></li>
					<li><a href="biz-ring.html?view=k" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image22','','../images/biz-ring/left_menu02_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image22','','../images/biz-ring/left_menu02_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu02_off.gif" name="Image22" width="161" border="0" id="Image22" alt="Biz-Ring Now" /></a></li>
					<li><a href="Advertising Schedule_list.html?view=k" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image24','','../images/biz-ring/left_menu03_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image24','','../images/biz-ring/left_menu03_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu03_off.gif" name="Image24" width="161" border="0" id="Image24" alt="Advertising Schedule" /></a></li>
					<li><a href="notice_list.html?view=k" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image25','','../images/biz-ring/left_menu04_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image25','','../images/biz-ring/left_menu04_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu04_off.gif" name="Image25" width="161" border="0" id="Image25" alt="Notice" /></a></li>
					<li><a href="price.html?view=k" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image26','','../images/biz-ring/left_menu05_on.gif',1)" onBlur="MM_swapImgRestore()" onFocus="MM_swapImage('Image26','','../images/biz-ring/left_menu05_on.gif',1),this.blur()"><img src="../images/biz-ring/left_menu05_off.gif" name="Image26" width="161" border="0" id="Image26" alt="Price Notice" /></a></li>
				</ul>
<%}%>
		    </div>
		</div>
	    <h2 class="hidden">contacts</h2>
		<div id="body_part">
			<div id="body_con">
				<p class="title" style="padding:72px 0 16px;"><img src="../images/biz-ring/sub_title01.gif" alt="Advertising Schedule" /></p>
				<div class="ta_top"></div>
				<div class="ta_bg">
					<div class="bs_con">
					<fieldset>
					<legend>schedule_list</legend>
						<table class="board01" cellpadding="0" cellspacing="0" border="0" summary="schedule_list">
							<caption style="position:absolute; width:0; height:0; font-size:0; line-height:0; overflow:hidden; visibility:hidden;">schedule_list</caption>
							<colgroup>
								<col style="width:150px" />
								<col style="" />
								<col style="width:110px" />
								<col style="width:110px" />
							</colgroup>
							<thead>
								<tr>
									<th width="262" scope="col"><div align="justify">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/biz-ring/board_title01.gif" alt="Date" align="absmiddle" /></div></th>
								  <th width="107" scope="col"><div align="justify">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/biz-ring/board_title02.gif" alt="Title" align="absmiddle" /></div></th>
								  <th width="159" scope="col"><div align="center">&nbsp;<img src="../images/biz-ring/board_title03.gif" alt="Advertisers" align="absmiddle" /></div></th>
								  <th width="62" scope="col"><div align="center"><img src="../images/biz-ring/board_title04.gif" alt="Run" align="absmiddle" /></div></th>

							  </tr>
							</thead>
							<tbody>
								<tr>
									<td colspan="4" height="10px" class="line"></td>
								</tr>
<%
	int rows = 12;
	int currPage = (request.getParameter("page") == null ? 1 : 
						request.getParameter("page").equals("0") ? 1 : Integer.parseInt(request.getParameter("page")));

	String connectionUrl = "jdbc:sqlserver://bizring.biz:14333;databaseName=bizring";
	String userid = "sa";
	String passwd = "qlalf@sql";
	
	// Declare the JDBC objects.
	java.sql.Connection con = null;
	java.sql.Statement stmt = null;
	java.sql.ResultSet rs = null;

	// Establish the connection.
	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

	try {   
		// Create and execute an SQL statement that returns some data.
		String SQL = "SELECT id, CONVERT(varchar, input_date, 106) as input_date, CONVERT (varchar, end_date, 106) as end_date, title, contents," + 
			"CASE status WHEN '0' THEN 'Reserved' WHEN '1' THEN 'Processing' WHEN '9' THEN 'Finished' ELSE status END as status" +
			", RowNum FROM ( SELECT t.id, t.input_date, t.end_date, t.title, t.contents, t.status, ROW_NUMBER() OVER (ORDER BY id desc) AS RowNum " +
			     	 "FROM web_board t WHERE t.category = 'adv_sch' ) AS MyDerivedTable WHERE MyDerivedTable.RowNum BETWEEN " + 
			     	 (rows * (currPage - 1) + 1) + " AND " + (rows * currPage);
		
		con = java.sql.DriverManager.getConnection(connectionUrl, userid, passwd);
		stmt = con.createStatement();
		rs = stmt.executeQuery(SQL);
		int displayedRow = 0;
		
		// Iterate through the data in the result set and display it.
		while (rs.next()) {
			displayedRow++;
			out.println("<tr>");
			out.println("<td class=\"date\">"+"<justify>" + rs.getString("input_date") +" "+ "-"+" "+ rs.getString("end_date")+"</justify>"+"</td>");
			if(view == null || view.equals("")){
				out.println("<td class=\"title\">"+"<justify>" + rs.getString("title") + "</justify>"+"</td>");
			}											 
			else if(view.equals("k")){
				out.println("<td class=\"title\"><a href=\"adv_schedule_modify.html?view=k&id=" + rs.getString("id") + "\">" + rs.getString("title") + "</a></td>");
			}
			out.println("<td>" +"<justify>" + rs.getString("contents") +"</justify>"+ "</td>");
			out.println("<td>" + "<justify>"+rs.getString("status") + "</justify>"+"</td>");
			out.print("</tr>");
		}
		for (int i = displayedRow; i < 12; i++)
			out.println("<tr><td class=\"date\"></td><td class=\"title\"></td><td></td><td></td></tr>");
    } catch (java.sql.SQLException e) {   
        e.printStackTrace();   
    } finally{   
        try {   
            if(stmt !=null) stmt.close();   
            if(con !=null) con.close();   
        } catch (java.sql.SQLException e) {   
            e.printStackTrace();   
        }   
    }   
%>
								<tr>
									<td colspan="4" height="10px" class="line"></td>
								</tr>
							</tbody>
						</table>
						<div class="board_navigation">
<%
	
	try {
		String counter = "SELECT count(1) as counter FROM web_board where category = 'adv_sch'";
		con = java.sql.DriverManager.getConnection(connectionUrl, userid, passwd);
		stmt = con.createStatement();
		rs = stmt.executeQuery(counter);
		int totalRecode = 0;
		while (rs.next()) {
			totalRecode = rs.getInt(1);
		}
		
		int totalPage = (int)(Math.ceil((double)totalRecode/rows));
		int viewFirst = ((int)(currPage-1)/10) * 10;
		int viewLast = ((int)(currPage-1)/10) * 10 + 9;
		
		String href = "";
		
		if(view == null || view.equals("")){
			if(viewFirst != 0){
				out.print("<a href=\"./adv_schedule?page=1\"><b>[First]</b></a>&nbsp;&nbsp; ");
				out.print("<a href=\"./adv_schedule?page=" + viewFirst + "\"><b>[Prev]</b></a>&nbsp;&nbsp; ");
			}
			
			for (int i = 0;i < totalPage; i++){						
				if (i == (currPage - 1)){
					href = "<span class=\"text_red\">" + (i + 1) + "</span>&nbsp;";
					out.print(href + " ");
				}
				else if( (i >= viewFirst) && (i <= viewLast) ){			
					href = "<a href=\"./adv_schedule?page=" + (i + 1) + "\">" + (i + 1) + "</a>&nbsp;&nbsp;";
					out.print(href + " ");
				}
			}
			
			if( (int)viewLast/10 != (int)totalPage/10){
				out.print("&nbsp;&nbsp;<a href=\"./adv_schedule?page=" + (viewLast + 2) + "\"><b>[Next]</b></a>");
				out.print("&nbsp;&nbsp;<a href=\"./adv_schedule?page=" + totalPage + "\"><b>[Last]</b></a> ");
			}
		}
		else if(view.equals("k")){
			if(viewFirst != 0){
				out.print("<a href=\"./adv_schedule?view=k&page=1\"><b>[First]</b></a>&nbsp;&nbsp; ");
				out.print("<a href=\"./adv_schedule?view=k&page=" + viewFirst + "\"><b>[Prev]</b></a>&nbsp;&nbsp; ");
			}
			
			for (int i = 0;i < totalPage; i++){						
				if (i == (currPage - 1)){
					href = "<span class=\"text_red\">" + (i + 1) + "</span>&nbsp;";
					out.print(href + " ");
				}
				else if( (i >= viewFirst) && (i <= viewLast) ){			
					href = "<a href=\"./adv_schedule?view=k&page=" + (i + 1) + "\">" + (i + 1) + "</a>&nbsp;&nbsp;";
					out.print(href + " ");
				}
			}
			
			if( (int)viewLast/10 != (int)totalPage/10){
				out.print("&nbsp;&nbsp;<a href=\"./adv_schedule?view=k&page=" + (viewLast + 2) + "\"><b>[Next]</b></a>");
				out.print("&nbsp;&nbsp;<a href=\"./adv_schedule?view=k&page=" + totalPage + "\"><b>[Last]</b></a> ");
			}
		}
		
	} catch (java.sql.SQLException e) {
		e.printStackTrace();
	} finally {
		try {   
            if(stmt !=null) stmt.close();   
            if(con !=null) con.close();   
        } catch (java.sql.SQLException e) {   
            e.printStackTrace();   
        }
	}
%>						
						</div>
<%if(view == null || view.equals("")){
}
else if(view.equals("k")){%>
						<div class="clear" style="padding-top:10px;text-align:right;"><a href="adv_schedule_write.html?view=k" onFocus="this.blur()"><img src="../images/common/btn_write.gif" alt="" /></a></div>
<%}%>	
					</fieldset>		
					</div>					
				</div>
				<div class="ta_bot"></div>
			</div>					
		</div>
	</div>
<jsp:include page="../bizring_footer1.jsp"/>
</BODY>
</HTML>

